package com.keya.features.tool;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.dcm4che3.data.Keyword;
import org.dcm4che3.data.Tag;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

/**
 * FindSCU 结果
 *
 * @author : xf.he
 * @version : 1.0 2023/11/2
 * @since : 1.0
 **/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class FindResult {

    Map<String, Object> resultMap;

    public String getString(int tag) {
        String name = Keyword.valueOf(tag);
        return resultMap.get(name) == null ? null : resultMap.get(name).toString();
    }

    public LocalDateTime studyTimeLocalDateTime() {
        String studyDate = getString(Tag.StudyDate);
        String studyTime = getString(Tag.StudyTime);
        String time = studyTime;
        int indexOf = studyTime.indexOf(".");
        if (indexOf != -1) {
            time = studyTime.substring(0, indexOf);
        }
        return LocalDateTime.parse(studyDate + time, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
    }
}

